definition: Given a language, defines a representation of his grammar, and defines an interpreter that uses the representation to interpret a sentence in a language.
Type: class behavior pattern
class Diagram:
The structure abstraction interpreter of the interpreter pattern : declares an abstract interface (or abstract class) to be implemented for all concrete
Design PHP
Interpreter mode definition(It is rarely encountered in real projects, so the theory goes first ...)
The interpreter mode is a solution for parsing according to the prescribed syntax, which is rarely used in current projects. It is defined as a representation of the method that defines a language, define an interpreter that uses this representation to
In Gof's design model: The basics of reusable object-oriented software, the interpreter pattern is said: Given a language, define a representation of its grammar, and define an interpreter that uses that representation to interpret the sentences in the language. If a particular type of problem occurs at a sufficiently high frequency, it might be worthwhile to describe each instance of the problem as a sente
/** * Declares an abstract interpretation operation * @author stone * */public interface Interpreter {public void interpret (context context); In practice, you can have a returned type that defines the data object that is interpreted}public class Xmlsaxinterpreter implements interpreter {@Overridepublic void interpret (context context) { SYSTEM.OUT.PRINTLN ("XML SAX In
Interpreter mode
The pattern we share with you today is the interpreter pattern.
First, explain what kind of problem the interpreter model is suitable to solve.
In fact, the problem with the interpreter pattern is that if a particular type of problem occurs on a high enough frequency, it may be worthwhile to express
Interpreter The schema provides a framework for implementing a syntax interpreter that uses an interpreter to provide a user with an interpreter that defines the language syntax, and interprets the sentences in the language through this interpreter.
Interpreter interpreter mode (behavioral mode)Motive (motivation)In the software construction process, if a particular area of the problem is more complex, similar patterns are repeated, if the use of ordinary programming to achieve will face very frequent changes.In this case, the problem of a particular domain is expressed as a sentence under some grammatical rule, and then an
Copy Code code as follows:
/**
* Interpreter Example
*
* @create_date: 2010-01-04
*/
Class Expression
{
function Interpreter ($STR)
{
return $str;
}
}
Class Expressionnum extends Expression
{
function Interpreter ($STR)
{
Switch ($STR)
{
Case "0": Return "0";
Case "1": Return "one";
Case "2": Return "two";
Case "3": Return "three";
Cas
Principle and Implementation interpreter mode of Atitit. linq java, atitit. linq Interpreter
Principles and implementation interpreter mode of Atitit. linq java
1. Implementation of Linq from where 1
2. Where expr Implementation 1
3. A variation of Attilax 2
4. interpreter mode structure 2
5. Code3
5.1. EqExpression3
Author: Chen Xi
Date: 11:31:12
Environment: [Mac 10.7.1 lion intel-based x64 gcc4.2.1 xcode4.2]
Reprinted please indicate the source
Q: What does the interpreter come from?
A: If it is a broad interpreter, you can understand it as a translator, as long as you can translate a thing that is regarded as original into what you need, processing can be called an interpreter
Python Interpreter: Part 1 function object, python InterpreterPython Interpreter: Part 1 function object
In the last three months, Ned Batchelder and I have spent a lot of time developing byterun. This project byterun (https://github.com/nedbat/byterun) is an interpreter for python bytecode developed using python. In the byterun process of the development
Interpreter definition: Define the grammar of the language and create an interpreter to interpret the sentences in that language.Interpreter seems to use the surface is not very wide, it describes how a language interpreter is constituted, in practical applications, we may rarely construct a language grammar. Let's just take a quick look.The first thing to do is
Interpreter Definition:Define the grammar of the language and create an interpreter to interpret the sentences in that language.
Interpreter seems to use the surface is not very wide, it describes how a language interpreter is constituted, in practical applications, we may rarely construct a language grammar. Let's ju
Do you know all the 25 php design patterns? The following code introduces the Interpreter mode (Interpreter mode )? Php * interpreter example...
25 php typesDesign ModeDo you all know? The following code is used to introduceInterpreter mode (Interpreter mode)
Interpreter (
Problem:In object-oriented design and development, it is often encountered that some requests or operations are difficult to express or process in the form of objects, for example, if we write a simple arithmetic computing tool to calculate "A + B", we can simply define a method, receive two variables, and perform arithmetic "+" to calculate the returned results, however, if we allow this method to implement the four arithmetic operations of "addition, subtraction, multiplication, division", we
Java Interpreter mode (Interpreter Mode)Interpreter definition: defines the grammar of a language and creates an Interpreter to explain sentences in the language. Interpreter seems to be not widely used. It describes how a language Inter
OverviewGiven a language, it defines a representation of its syntax and an interpreter that uses this representation to interpret sentences in the language.ApplicabilityWhen a language needs to be interpreted and executed, and you can represent sentences in the language as an abstract syntax tree, you can use the interpreter mode. This mode works best in the following situations:This grammar is simple for c
Defined in Gof:"Defines the statements required by a programming language and provides an explanation to parse (execute) the language. ”Traditionally, the execution of program code is usually done in two waysFirst: Compile the programThe second type: InterpreterCommon use of the Interpreter programming languageIncludes scripting languages in the field of popular and web designsuch as JavaScript, PHP, Ruby, etc.These program code is written after the g
Interpreter mode: Creates an interpreter for the language, providing a way to evaluate the language's syntax or expression.Example: Public InterfaceExpression { Public Abstract Booleaninterpret (String context); Public classTerminalexpressionImplementsExpression {PrivateString data; Publicterminalexpression (String data) { This. data =data; } @Override Public Booleaninterpret (String context) {if(Context.c
Structure
Intention
Given a language, define a representation of its grammar and define an interpreter that interprets the sentences in the language using that representation.
Applicability
You can use the interpreter pattern when there is a language that needs to be interpreted and executed, and you can represent a sentence in that language as an
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.